//
//  LGTRWZOrderViewCell.swift
//  KJLGT
//
//  Created by jenkin on 2019/8/20.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit

class LGTRWZOrderViewCell: UITableViewCell {

    var moneyLabel:UILabel?
    var titleLabel:UILabel?
    var timeLabel:UILabel?
    var stateLabel:UILabel?
    private var _orderModel:TaskOrderModel?
    var orderModel:TaskOrderModel?{
        get{
            return _orderModel
        }set{
            _orderModel = newValue
            self.setData()
        }
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        let imageView:UIImageView = LGTViewCreateUtil.share.createImageView(image: "earn")
        self.addSubview(imageView)
        imageView.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFit(9))
            make.top.equalTo(11)
            make.height.equalTo(SizeFit(49))
            make.width.equalTo(SizeFit(51))
            make.bottom.equalTo(-SizeFit(9))
        }
        
        self.moneyLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.center, textColor: RedColor, fontSize: SizeFitFloat(19), text: "")
        self.addSubview(self.moneyLabel!)
        self.moneyLabel?.snp.makeConstraints({ (make) in
            make.center.equalTo(imageView)
            make.height.equalTo(SizeFitFloat(19))
            make.width.equalTo(SizeFit(51))
        })
        
        let line = LGTViewCreateUtil.share.createLineView()
        self.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFit(12))
            make.right.equalTo(-SizeFit(4))
            make.height.equalTo(1)
            make.bottom.equalTo(0)
        }
        
        self.titleLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(14), text: "简单注册")
        self.addSubview(self.titleLabel!)
        self.titleLabel?.snp.makeConstraints({ (make) in
            make.left.equalTo(imageView.snp_rightMargin).offset(SizeFit(12))
            make.height.equalTo(SizeFit(12))
            make.width.equalTo(SizeFit(200))
            make.top.equalTo(SizeFit(17))
        })
        
        self.timeLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(10), text: "完成时间")
        self.addSubview(self.timeLabel!)
        self.timeLabel?.snp.makeConstraints({ (make) in
            make.left.equalTo(imageView.snp_rightMargin).offset(SizeFit(12))
            make.height.equalTo(SizeFit(10))
            make.width.equalTo(SizeFit(200))
            make.bottom.equalTo(imageView).offset(-SizeFit(3))
        })
        
        
        //FF1A1A  46B25F 999999 FFB21A 999999 333333 3BB1EE
        self.stateLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.right, textColor: TextColor, fontSize: SizeFitFloat(15), text: "状态值")
        self.addSubview(self.stateLabel!)
        self.stateLabel?.snp.makeConstraints({ (make) in
            make.right.equalTo(SizeFitFloat(-12))
            make.height.equalTo(SizeFit(12))
            make.centerY.equalTo(self)
        })
    }
    
    func setData(){
        let status = self.orderModel?.status ?? 0
        let key:String = "\(status)"
        let data:Dictionary<String, Any> = RWZOrderStateInfo[key] as! Dictionary<String, Any>
        let price:Int = self.orderModel?.task?.price ?? 0
        self.moneyLabel?.text = "\(price)"
        self.titleLabel?.text = self.orderModel?.task?.title ?? ""
        
        
        //    "14":["title":"介入未通过", "color": ColorUtil(color: 0xFF551A),"time":"介入处理时间："]]
        let timeStr:String = data["time"] as? String ?? ""
        let stateStr:String = data["title"] as? String ?? ""
        self.stateLabel?.text = stateStr
        
        let time:String = self.orderModel?.update_time ?? ""
        self.timeLabel?.text = "\(timeStr)\(time)"
        self.stateLabel?.textColor = data["color"] as? UIColor ?? TextColor
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
